<?php
/**
 * Created by PhpStorm.
 * User: hcadmin
 * Date: 16/8/30
 * Time: 下午3:15
 */
namespace app\controllers;

use app\common\CommonHelper;
use app\common\Easemob;
use app\models\Admin_admin;
use app\models\Bar_bar;
use app\models\Dynamic_comment;
use app\models\Dynamic_dynamic;
use app\models\Gl_city;
use app\models\Gl_banner;
use app\models\Gl_feedback;
use app\models\Gl_gifttemp;
use app\models\Gl_report;
use app\models\Order_order;
use app\models\Party_party;
use app\models\Pay_pay;
use app\models\User;
use app\models\User_user;
use app\models\User_userparty;
use app\models\User_sort;
use app\models\Bar_claim;
use Yii;

require dirname(dirname(__FILE__)).'/excel/PHPExcel.php';//导入excel
date_default_timezone_set("Asia/Shanghai");


//引入又拍云
require_once ('../web/upyun/upyun.class.php');

class BackstageappController extends BackbaseController{
    public $layout = 'backstageapp';

    public function actionLogin(){

        // 获取cookie

        if (isset($_COOKIE["admin_id"])) {

            return $this->redirect('dynamic-list');
        } else {

            $request = yii::$app->request->post();

            if ($request) {

                $model = new Admin_admin();

                $admin = $model->findByUsername($request['mobile'] , md5($request['password']));

                if($admin){
                    setcookie("admin_mobile", $request['mobile'], time() + (3600 * 24 * 10),'/',null,null,true);
                    setcookie("admin_id",$admin['admin_id'],time() + (3600 * 24 * 10),'/',null,null,true);
//                  登录成功
                    return 0;
                }else{
                    //登录失败
                    return 1;
                }

            } else {
                return $this->renderPartial('login');
            }
        }
    }

    // 退出登录
    public function actionLoginOut(){

        setcookie("admin_mobile", false, time() - 600,'/');
        setcookie("admin_id",false,time() - 600,'/');

        return $this->renderPartial('login');
    }

    //获取充值列表
    public function actionRechargelist() {
        $request = yii::$app->request->get();
        $model = new Pay_pay();

        $limit = $request['limit'];
        $offset = $request['offset'];
        $startTime = -1;
        $endTime = -1;
        $userName = -1;
        $payType = -1;
        $cityCode = -1;

        if (isset($request['start_date'])) {
            $startTime = $request['start_date'];
            $endTime = $request['end_date'];
        }

        if (isset($request['user_name'])) {
            $userName = $request['user_name'];
        }

        if (isset($request['city_code']))
            $cityCode = $request['city_code'];

        if (isset($request['pay_type'])) {
            $payType = $request['pay_type'];
        }
        $payList = $model->getRechargeLists($limit, $offset, $startTime, $endTime, $userName, $payType, $cityCode);
        return json_encode($payList);
    }

    /**
     *动态列表页面
     */
    public function actionDynamicList(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 182;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('dynamic-management/dynamic-list',['cities'=>$cities]);
    }

    /**
     * 动态详情
     */
    public function actionDynamicDetail(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 183;

        $request = yii::$app->request->get();
        $dynamic_id = $request['dynamic_id'];

        $barModel = new Bar_bar();
        $bars = $barModel->getBars();

        $dynamicModel = new Dynamic_dynamic();
        $dynamic = $dynamicModel->getDynamic($dynamic_id);

        return $this->render('dynamic-management/dynamic-detail',['bars'=>$bars,'dynamic_id'=>$dynamic_id,'dynamic'=>$dynamic]);
    }

    public function actionAddDynamic(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 184;

        $barModel = new Bar_bar();
        $bars = $barModel->getBars();

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        $bar = [];
        $request = yii::$app->request->get();
        if(isset($request['bar_id'])) {
            $barId = $request['bar_id'];
            $bar = Bar_bar::findOne($barId);
        }

        return $this->render('dynamic-management/add-dynamic',['bars'=>$bars,'cities'=>$cities,'bar'=>$bar]);
    }

    // 修改动态时间
    public function actionDynamicTime(){
        $request = yii::$app->request->post();
        $model = new Dynamic_dynamic();
        $dynamicId = $request['dynamic_id'];
        $gmtPublish = strtotime($request['gmt_publish']) * 1000;

        $result = $model->editGmtpublish($dynamicId, $gmtPublish);
        if ($result > 0) {
            return json_encode(['code' => 0, 'msg' => '更新成功']);
        } else {
            return json_encode(['code' => 1, 'msg' => '更新失败']);
        }
    }

    //获取动态列表
    public function actionDynamicData() {
        $request = yii::$app->request->get();
        $model = new Dynamic_dynamic();
        $limit = $request['limit'];
        $offset = $request['offset'];
        $barId = -1;
        $cityCode = -1;
        $startTime = -1;
        $endTime = -1;
        $userId = -1;
        $dynamicTitle = -1;
        $dynamicBar = -1;
        $dynamicUser = -1;
        $sortType = -1;

        if (isset($request['bar_id'])) {
            $barId = $request['bar_id'];
        }
        if (isset($request['city_code'])) {
            $cityCode = $request['city_code'];
        }
        if (isset($request['start_date'])) {
            $startTime = $request['start_date'];
            $endTime = $request['end_date'];
        }
        if (isset($request['user_id'])) {
            $userId = $request['user_id'];
        }
        if (isset($request['dynamic_title'])) {
            $dynamicTitle = $request['dynamic_title'];
        }

        if (isset($request['dynamic_bar'])) {
            $dynamicBar = $request['dynamic_bar'];
        }

        if (isset($request['dynamic_user'])) {
            $dynamicUser = $request['dynamic_user'];
        }

        if (isset($request['sort_type'])) {
            $sortType = $request['sort_type'];
        }

        $dynamicList = $model->getDynamicList($limit, $offset, $barId, $cityCode, $startTime, $endTime, $userId, $dynamicTitle,$dynamicBar,$dynamicUser,$sortType);
        return json_encode($dynamicList);
    }

    // 修改动态权重值
    public function actionDynamicWeight() {
        $request = yii::$app->request->post();
        $model = new Dynamic_dynamic();

        $dynamicId = $request['dynamic_id'];
        $weight = $request['weight_value'];
        $data = Dynamic_dynamic::findOne($dynamicId);

        $data->weight_value = $weight;

        if ($data->save() > 0) {
            return json_encode(['code'=>0,'msg'=>"修改成功"]);
        } else {
            return json_encode(['code'=>1,'msg'=>"修改失败"]);
        }
    }

    // 调整点赞、浏览量
    public function actionEidtAdjustment() {
        $request = yii::$app->request->post();
        $model = new Dynamic_dynamic();

        $dynamicId = $request['dynamic_id'];
        $likeCount = $request['like_count'];
        $browseCount = $request['browse_count'];

        $result = $model->editAdjustment($dynamicId, $likeCount, $browseCount);

        if ($result) {
            return json_encode(['code'=>0,'msg'=>"修改成功"]);
        } else {
            return json_encode(['code'=>1,'msg'=>"修改失败"]);
        }
    }

//  加载添加页面
    public function actionAddVest(){
        $model = new User_sort();
        $sort = $model->showSort();

        $adminModel = new Admin_admin();
        $admin = $adminModel->showAdmin();

        return json_encode(['sort'=>$sort, 'admin'=>$admin]);
    }

    // 添加马甲
    public function actionInsertVest(){
        $request = yii::$app->request->post();
        $model = new User_user();

        $userId = $request['user_id'];
        $sortId = $request['sort_id'];
        $adminId = $request['admin_id'];
        $userSign = $request['user_sign'];

        $result = $model->addVest($userId, $sortId, $adminId, $userSign);

        if ($result) {
            return json_encode(['code'=>0,'msg'=>"添加成功"]);
        } else {
            return json_encode(['code'=>1,'msg'=>"添加失败"]);
        }
    }

//    加载重分配页面
    public function actionReDistribution() {
        $adminModel = new Admin_admin();
        $admin = $adminModel->showAdmin();

        return json_encode($admin);
    }

//    修改马甲归属
    public function actionEditAscription() {
        $request = yii::$app->request->post();
        $userId = $request['user_id'];
        $adminId = $request['admin_id'];

        $model = new User_user();
        $result = $model->editAscription($userId, $adminId);

        if ($result) {
            return json_encode(['code'=>0, 'msg'=>'分配成功']);
        } else {
            return json_encode(['code'=>1, 'msg'=>'分配失败']);
        }
    }


    public function actionCommentDetail(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 185;

        $userModel = new User_user();
        $users = $userModel->getVestUser(100,0,-1,-1,-1);

        $request = yii::$app->request->get();
        $commentId = $request['comment_id'];
        $dynamicId = $request['dynamic_id'];

        $commentModel = new Dynamic_comment();
        $targetComment = $commentModel->getCommentData($commentId);

        return $this->render('dynamic-management/comment-detail',['users'=>$users['rows'],'comment_id'=>$commentId,'dynamic_id'=>$dynamicId,'first_comment'=>$targetComment]);
    }

    public function actionCommentData(){
        $request = yii::$app->request->get();
        $limit = $request['limit'];
        $offset = $request['offset'];
        $commentId = $request['comment_id'];

        $model = new Dynamic_comment();
        $result = $model->getSecondComments($commentId,$limit,$offset);

        for($position=0;$position<count($result['rows']);$position++){
            $secondComment = $result['rows'][$position];
            if($secondComment['comment_level'] == 3){
                $targetComment = $model->getCommentData($secondComment['second_comment_id']);
                $result['rows'][$position]['target_comment'] = $targetComment;
            }
        }

        return json_encode($result);
    }

    public function actionVestList(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 162;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('vest-management/vest-list',['cities'=>$cities]);
    }

//    修改马甲状态
    public function actionVestType() {
        $request = yii::$app->request->post();

        $userId = $request['vest_id'];
        $userType = $request['is_deleted'];

        $model = new User_user();
        $result = $model->editVestUser($userId, $userType);

        if ($result) {
            return json_encode(['code' => 0, 'msg' => '更新成功']);
        } else {
            return json_encode(['code' => 1, 'msg' => '更新失败']);
        }
    }

    public function actionVestData(){
        $request = yii::$app->request->get();
        $limit = $request['limit'];
        $offset = $request['offset'];
        $userStatus = -1;
        $userName = -1;
        $cityCode = -1;

        if (isset($request['city_code'])) {
            $cityCode = $request['city_code'];
        }
        if (isset($request['user_name'])) {
            $userName = $request['user_name'];
        }
        if (isset($request['user_stauts'])) {
            $userStatus = $request['user_stauts'];
        }

        $model = new User_user();
        $result = $model->getVestUser($limit,$offset,$userStatus,$userName,$cityCode);

        return json_encode($result);
    }

    public function actionVestEase(){
        $request = yii::$app->request->get();
        $limit = $request['limit'];
        $offset = $request['offset'];
        $userStatus = -1;
        $userName = -1;
        $cityCode = -1;

        if (isset($request['city_code'])) {
            $cityCode = $request['city_code'];
        }
        if (isset($request['user_name'])) {
            $userName = $request['user_name'];
        }
        if (isset($request['user_stauts'])) {
            $userStatus = $request['user_stauts'];
        }

        $model = new User_user();
        $result = $model->getVestUser($limit,$offset,$userStatus,$userName,$cityCode);

        $commonModel = new CommonHelper();
        $easeIdPre = $commonModel->getEaseIdPre();

        $hxModel = new Easemob();
        for($index=0;$index<count($result['rows']);$index++){
            $result['rows'][$index]['offline_count'] = $hxModel->getOfflineMessages($easeIdPre.$result['rows'][$index]['user_id']);
        }

        return json_encode($result);
    }

    public function actionVestDetail(){
        $request = yii::$app->request->get();
        $userId = $request['user_id'];
        $menuitemid = $request['menuitemid'];

        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = $menuitemid;

        $user = User_user::findOne($userId);

        return $this->render('vest-management/vest-detail',['user'=>$user]);
    }

    public function actionVest(){
        $request = yii::$app->request->post();
        $user_id = $request['user_id'];
        $user_name =  $request['user_name'];
        $photos = -1;
        $sign = -1;
        if(isset($request['photos'])){
            $photos = $request['photos'];
        }

        if(isset($request['sign'])){
            $sign = $request['sign'];
        }

        $model = new User_user();

        if ($model->updateVestData($user_id,$user_name,$photos,$sign) > 0) {
            return json_encode(['code'=>0,'msg'=>"修改成功"]);
        } else {
            return json_encode(['code'=>1,'msg'=>"修改失败"]);
        }
    }

    /**
     * 又拍云上传图片
     *
     * api
     * post
     */
    public function actionImgUpload()
    {

        if (isset($_POST['x'])) {
            $imgtype = array(
    //            'gif'=>'gif',
                'png'=>'png',
                'jpg'=>'jpeg',
                'jpeg'=>'jpeg'
            ); //图片类型在传输过程中对应的头信息
            $message = $_POST['message']; //接收以base64编码的图片数据
            $filename = $_POST['filename']; //接收文件名称
            $ftype = $_POST['filetype'];  //接收文件类型
            //首先将头信息去掉，然后解码剩余的base64编码的数据
            $message = base64_decode(substr($message,strlen('data:image/'.$imgtype[strtolower($ftype)].';base64,')));
            $filename = date('U').rand(0,9999).".".$ftype;
            $furl = "../web/imgUpload/";

            //开始写文件
            $filePath = $furl.date('U').rand(0,9999).$filename;

            //裁剪图片
            $src_path = $filePath;
            //创建源图的实例
            $src = imagecreatefromstring($message);

            $x = $_POST['x'];
            $y = $_POST['y'];
            //裁剪区域的宽和高
            $width = $_POST['width'];
            $height = $_POST['height'];
            //最终保存成图片的宽和高，和源要等比例，否则会变形
            $final_width = 800;
            $final_height = $final_width * $height / $width;

            //将裁剪区域复制到新图片上，并根据源和目标的宽高进行缩放或者拉升
            $new_image = imagecreatetruecolor($final_width, $final_height);
            imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);

            //输出图片
            if ($ftype == $imgtype['jpg']) {
                header('Content-Type: image/jpeg');
                imagejpeg($new_image, $src_path);
            } else {
                header('Content-Type: image/png');
                imagepng($new_image, $src_path);
            }
            imagedestroy($src);
            imagedestroy($new_image);

            //又拍云配置
            $config =  array(
                'user_name' => 'hoooty168',
                'pwd' => 'hotcity168',
                'bucket' => 'hotcity-images',
                'picture_path' => $filePath,
            );

            //图片上传到又拍云
            $upyun = new \UpYun($config['bucket'], $config['user_name'], $config['pwd']);
            $filePath = str_replace('..',dirname(__DIR__),$filePath);
            $imgName = explode('imgUpload/',$filePath)[1];

            $src='';  //图片src
            //清除图片缓存
            //循环目录下的所有文件
            function delFileUnderDir( $dirName="../web/imgUpload/" )
            {
                if ( $handle = opendir( "$dirName" ) ) {
                    while ( false !== ( $item = readdir( $handle ) ) ) {
                        if ( $item != "." && $item != ".." ) {
                            if ( is_dir( "$dirName/$item" ) ) {
                                delFileUnderDir( "$dirName/$item" );
                            } else {
                                if( unlink( "$dirName/$item" ) );
                            }
                        }
                    }
                    closedir( $handle );
                }
            }
            if (fopen($filePath,'r')){
                $fh = fopen($filePath,'r');
                // 获取图片体积大小
                $limit = $_POST['limit']; //限制图片大小
                $size = filesize($filePath);
                if($size>$limit){
                    fclose($fh);
//                delFileUnderDir('imgUpload');
                    echo json_encode(array('code'=>2,'msg'=>'图片尺寸不符合','size'=>$size));
                }else{
                    $dateString = date("Y-m-d");
                    $upyun->writeFile('/WebHotCity_2.0/'.$dateString.'/'.$imgName, $fh, True);   // 上传图片，自动创建目录
                    $src = $config['bucket'].".b0.upaiyun.com"."/WebHotCity_2.0/".$dateString.'/'.$imgName;
                    fclose($fh);
//                delFileUnderDir('imgUpload');
                    echo json_encode(array('code'=>0,'msg'=>'图片上传成功','imgSrc'=>'http://'.$src));
                }
            }else{
                echo json_encode(array('code'=>1,'msg'=>'图片上传失败'));
            }
        } else {
            $data = $_FILES;

            // 文件存储目录
            $dir = "../web/imgUpload/";

            // 循环数据获取到文件路径
            $arrdata = [];
            $localname = "";
            $ext = "png";
            foreach ($data as $key => $val) {
                //获取文件的后缀,pathinfo()会以数组的形式返回一个文件的路径信息，其中extension元素则是文件的后缀名
                $ext = pathinfo($val['name'])['extension'];

                //最终文件名为
                $localname = $val['tmp_name'];

                if (move_uploaded_file($val['tmp_name'], $localname)) {
                    $arrdata[$key] = $localname;
                }
            }
            $filePath = $localname;

            //又拍云配置
            $config =  array(
                'user_name' => 'hoooty168',
                'pwd' => 'hotcity168',
                'bucket' => 'hotcity-images',
                'picture_path' => $filePath,
            );

            $filename = date('U').rand(0,9999).'.'.$ext;
            //图片上传到又拍云
            $upyun = new \UpYun($config['bucket'], $config['user_name'], $config['pwd']);
            $filePath = str_replace('..',dirname(__DIR__),$filePath);
            $imgName = $filename;

            $src='';  //图片src
            //清除图片缓存
            //循环目录下的所有文件
            function delFileUnderDir( $dirName="../web/imgUpload/" )
            {
                if ( $handle = opendir( "$dirName" ) ) {
                    while ( false !== ( $item = readdir( $handle ) ) ) {
                        if ( $item != "." && $item != ".." ) {
                            if ( is_dir( "$dirName/$item" ) ) {
                                delFileUnderDir( "$dirName/$item" );
                            } else {
                                if( unlink( "$dirName/$item" ) );
                            }
                        }
                    }
                    closedir( $handle );
                }
            }
            if (fopen($filePath,'r')){
                $fh = fopen($filePath,'r');
                $dateString = date("Y-m-d");
                $upyun->writeFile('/WebHotCity_2.0/'.$dateString.'/'.$imgName, $fh, True);   // 上传图片，自动创建目录
                $src = $config['bucket'].".b0.upaiyun.com"."/WebHotCity_2.0/".$dateString.'/'.$imgName;
                fclose($fh);
//                delFileUnderDir('imgUpload');
                echo json_encode(array('code'=>0,'msg'=>'图片上传成功','imgSrc'=>'http://'.$src));
            }else{
                echo json_encode(array('code'=>1,'msg'=>'图片上传失败'));
            }
        }
    }
    
    //修改动态状态
    public function actionOperateDynamic(){
        $request = yii::$app->request->post();

        $model = new Dynamic_dynamic();
        if($model->changeDynamicStatus($request['dynamic_id'],$request['type']) > 0)
            return json_encode(['code'=>0,'msg'=>'修改成功']);
        else
            return json_encode(['code'=>1,'msg'=>'修改失败']);
    }

    //获取动态礼物列表
    public function actionDynamicGifts(){
        $request = yii::$app->request->get();
        $dynamic_id = $request['dynamic_id'];
        $limit = $request['limit'];
        $offset = $request['offset'];

        $model = new Order_order();
        $result = $model->getDynamicGift($dynamic_id,$limit,$offset);

        return json_encode($result);
    }

    //获取动态评论列表
    public function actionDynamicComments(){
        $request = yii::$app->request->get();
        $dynamic_id = $request['dynamic_id'];
        $limit = $request['limit'];
        $offset = $request['offset'];

        $model = new Dynamic_comment();
        $result = $model->getFirstComments($dynamic_id,$limit,$offset);

        for($index=0;$index<count($result['rows']);$index++){
            $second_comments = $model->getSecondComments($result['rows'][$index]['comment_id'],2,0);

            for($position=0;$position<count($second_comments['rows']);$position++){
                $secondComment = $second_comments['rows'][$position];
                if($secondComment['comment_level'] == 3){
                    $targetComment = $model->getCommentData($secondComment['second_comment_id']);
                    $second_comments['rows'][$position]['target_comment'] = $targetComment;
                }
            }
            $result['rows'][$index]['second_comments'] = $second_comments['rows'];
        }
        return json_encode($result);
    }

    //修改评论状态
    public function actionOperateComment(){
        $request = yii::$app->request->post();
        
        $model = new Dynamic_comment();
        if($model->changeCommentStatus($request['comment_id'],$request['type']) > 0)
            return json_encode(['code'=>0,'msg'=>'修改成功']);
        else
            return json_encode(['code'=>1,'msg'=>'修改失败']);
    }

    // 展示奖品列表页面
    public function actionGiftList() {
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 102;

//        $barModel = new Bar_bar();
//        $bars = $barModel->getBars();

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('gift-management/gift-list',['cities'=>$cities]);
    }

    // 查询编辑所需数据
    public function actionGiftEdit() {
        $requestPost = yii::$app->request->post();
        $model = new Gl_gifttemp();
        $gifttemp_code = $requestPost['gifttemp_code'];

        $editgift = $model->editgiftTemp($gifttemp_code);
        return json_encode($editgift);
    }

    //获取奖品列表  更新奖品资料 新建奖品
    public function actionGifttemps() {
        $request = yii::$app->request->get();
        $model = new Gl_gifttemp();
        if ($request) {
            //获取奖品列表
            $limit = $request['limit'];
            $offset = $request['offset'];
            $userName = -1;

            if (isset($request['user_name'])) {
                $userName = $request['user_name'];
            }

            $giftTemps = $model->getGiftTempList($limit, $offset, $userName);
            return json_encode($giftTemps);
        } else {
            //更新奖品资料
            $requestPost = yii::$app->request->post();
            if ($requestPost) {
                $giftTempCode = $requestPost['gifttemp_code'];
                $giftTempName = -1;
                $giftTempPic = -1;
                $giftTempPirce = -1;
                $giftTempRank = -1;
                $isDeleted = -1;
                if (isset($requestPost['gifttemp_name']))
                    $giftTempName = $requestPost['gifttemp_name'];
                if (isset($requestPost['gifttemp_pic']))
                    $giftTempPic = $requestPost['gifttemp_pic'];
                if (isset($requestPost['gifttemp_pirce']))
                    $giftTempPirce = $requestPost['gifttemp_pirce'];
                if (isset($requestPost['gifttemp_rank']))
                    $giftTempRank = $requestPost['gifttemp_rank'];
                if (isset($requestPost['status']))
                    $isDeleted = $requestPost['status'];

                $updateDone = $model->updateGiftTemp($giftTempCode, $giftTempName, $giftTempPic, $giftTempPirce, $giftTempRank, $isDeleted);
                if ($updateDone) {
                    return json_encode(['code'=>0,'msg'=>"更新成功"]);//更新成功
                } else {
                    return json_encode(['code'=>1,'msg'=>"更新失败"]);
                }
            }
        }
    }

    // 添加奖品
    public function actionAddGift() {
        //新建奖品
        $requestPost = yii::$app->request->post();
        $model = new Gl_gifttemp();

        $model->gifttemp_name = $requestPost['gifttemp_name'];
        $model->gifttemp_pic = $requestPost['gifttemp_pic'];
        $model->gifttemp_pirce = $requestPost['gifttemp_pirce'];
        $model->is_deleted = 0;
        $model->gmt_create=date('Y-m-d H:i:s',time());
        $model->gmt_modified=date('Y-m-d H:i:s',time());

        $count = $model->insert();
        if ($count>0) {
            return json_encode(['code'=>0,'msg'=>"新建成功"]);
        } else {
            return json_encode(['code'=>1,'msg'=>"新建失败"]);
        }
    }

    // 加载举报列表页面
    public function actionReportList() {
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 132;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('report-management/report-list',['cities'=>$cities]);
    }

    //获取举报列表  设置举报状态
    public function actionReport() {
        $requestGet = yii::$app->request->get();
        $model = new Gl_report();
        if ($requestGet) {
            //获取举报列表
            $limit = $requestGet['limit'];
            $offset = $requestGet['offset'];
            $reportStatus = -1;
            $startTime = -1;
            $endTime = -1;
            $reportType = -1;
            $cityCode = -1;

            if (isset($requestGet['city_code'])){
                $cityCode = $requestGet['city_code'];
            }

//            if (isset($requestGet['report_state'])){
//                $reportStatus = $requestGet['report_state'];
//            }

            if (isset($requestGet['report_state'])){
                $reportStatus = $requestGet['report_state'];
            }

            if (isset($requestGet['start_date'])) {
                $startTime = $requestGet['start_date'];
                $endTime = $requestGet['end_date'];
            }
            if (isset($requestGet['report_type']))
                $reportType = $requestGet['report_type'];

            $reportList = $model->getReportList($limit, $offset, $startTime, $endTime, $reportType, $cityCode, $reportStatus);
            return json_encode($reportList);
        } else {
            $requestPost = yii::$app->request->post();
            $reportId = $requestPost['report_id'];
            $isDeleted = $requestPost['is_deleted'];
            $updateDone = $model->updateReport($reportId, $isDeleted);
            
            if ($updateDone) {
                return json_encode(["code" => 0, "msg" => "更新成功"]);//更新成功
            } else {
                return json_encode(["code" => 1, "msg" => "更新失败"]);
            }
        }
    }

//    查看举报详情
    public function actionReportDetails() {
        $request = yii::$app->request->get();
        $reportType = $request['report_type'];
        $reportId = $request['report_id'];

        $model = new Gl_report();
        $targetId = $model->findTarget($reportId);

        if ($reportType == 2) {
            $this -> confirmAdmin();
            $view = Yii::$app->view;
            $view->params['menuitemid'] = 183;

            $dynamic_id = $targetId['target_id'];

            $barModel = new Bar_bar();
            $bars = $barModel->getBars();

            $dynamicModel = new Dynamic_dynamic();
            $dynamic = $dynamicModel->getDynamic($dynamic_id);

            return $this->render('dynamic-management/dynamic-detail',['bars'=>$bars,'dynamic_id'=>$dynamic_id,'dynamic'=>$dynamic]);

        } elseif ($reportType == 3) {
            $this -> confirmAdmin();
            $view = Yii::$app->view;
            $view->params['menuitemid'] = 185;

            $userModel = new User_user();
            $users = $userModel->getVestUser(100,0,-1,-1,-1);

            $request = yii::$app->request->get();
            $commentId = $targetId;

            $commentModel = new Dynamic_comment();
            $targetComment = $commentModel->getCommentData($commentId);

            return $this->render('dynamic-management/comment-detail',['users'=>$users['rows'],'comment_id'=>$commentId['target_id'],'dynamic_id'=>$targetComment['dynamic_id'],'first_comment'=>$targetComment, 'del'=>'1']);
        }

        return json_encode($targetId);
    }

    // 加载意见列表页面
    public function actionFeedbackList() {
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 122;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();
        
        return $this->render('feedback-management/feedback-list',['cities'=>$cities]);
    }

    //获取意见列表 设置意见状态
    public function actionFeedback() {
        $requestGet = yii::$app->request->get();
        $model = new Gl_feedback();
        if ($requestGet) {
            //获取意见列表
            $limit = $requestGet['limit'];
            $offset = $requestGet['offset'];
            $cityCode = -1;
            $status = -1;
            $startTime = -1;
            $endTime = -1;
            $feedbackStatus = -1;
            $userName = -1;

            if (isset($requestGet['city_code'])) {
                $cityCode = $requestGet['city_code'];
            }

            if (isset($requestGet['start_date'])) {
                $startTime = $requestGet['start_date'];
                $endTime = $requestGet['end_date'];
            }
            if (isset($requestGet['feedback_status'])) {
                $feedbackStatus = $requestGet['feedback_status'];
            }

            if (isset($requestGet['user_name']))
                $userName = $requestGet['user_name'];

            $feedBack = $model->getFeedbackLists($limit, $offset,$cityCode, $startTime, $endTime, $endTime, $feedbackStatus);

            return json_encode($feedBack);
        } else {
            $requestPost = yii::$app->request->post();
            $feedBackId = $requestPost['feedback_id'];
            $feedbackRmk = -1;
            $status = -1;

            if (isset($requestPost['status'])) {
                $status = $requestPost['status'];
            }
            if (isset($requestPost['feedback_rmk'])) {
                $feedbackRmk = $requestPost['feedback_rmk'];
            }
            $updateDone = $model->updateFeedbackStatus($feedBackId, $status, $feedbackRmk);
            if ($updateDone) {
                return json_encode(["code" => 0, "msg" => "更新成功"]);//更新成功
            } else {
                return json_encode(["code" => 1, "msg" => "更新失败"]);
            }
        }
    }

//    查看意见备注
    public function actionShowRemarks() {
        $request = yii::$app->request->post();
        $model = new Gl_feedback();
        $feedbackId = $request['feedback_id'];

        $feedbackRmk = $model->showFeedbackRmk($feedbackId);

        return json_encode($feedbackRmk);
    }

    // 查看意见详情
    public function actionOpinionDetails() {
        $request = yii::$app->request->post();
        $model = new Gl_feedback();
        $feedbackId = $request['feedback_id'];

        $result = $model->showFeedbackRmk($feedbackId);

        return json_encode($result);
    }

    //获取用户列表
    public function actionUsers(){
        $requestGet = yii::$app->request->get();
        $model = new User_user();
        $limit = $requestGet['limit'];
        $offset = $requestGet['offset'];
        $cityCode = -1;
        $userType = -1;
        $startTime = -1;
        $endTime = -1;
        $userName = -1;
        $userSort = -1;

        if (isset($requestGet['user_sort'])) {
            $userSort = $requestGet['user_sort'];
        }

        if (isset($requestGet['city_code'])){
            $cityCode = $requestGet['city_code'];
        }

        if (isset($requestGet['start_date'])) {
            $startTime = $requestGet['start_date'];
            $endTime = $requestGet['end_date'];
        }


        if (isset($requestGet['user_type'])) {
            $userType = $requestGet['user_type'];
        }

        if (isset($requestGet['user_name'])){
            $userName = $requestGet['user_name'];
        }

        $users = $model->getUserLists($limit, $offset,$cityCode,$startTime,$endTime,$userName,$userType, $userSort);
        return json_encode($users);
    }

    public function actionBarList(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 172;

//        $barModel = new Bar_bar();
//        $bars = $barModel->getBars();

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();
        return $this->render('bar-management/bar-list',['cities'=>$cities]);
    }

    public function actionBarDetail() {
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 173;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        $requestGet = yii::$app->request->get();
        $barId = $requestGet['bar_id'];
        $bar = Bar_bar::findOne($barId);

        return $this->render('bar-management/bar-detail',['cities'=>$cities,'bar'=>$bar]);
    }

    //新建酒吧
    public function actionBar() {
        //新建酒吧
        $requestPut = yii::$app->request;
        $model = new Bar_bar();
        if ($requestPut->isPut) {
            $param = $requestPut->bodyParams;
            if (isset($param['bar_name'])) {
                $model->bar_name = $param['bar_name'];
            } else {
                return '请输入商家名字';
            }
            if (isset($param['city_code'])) {
                $model->city_code = $param['city_code'];
            } else {
                return '请选择城市';
            }
            if (isset($param['bar_address'])) {
                $model->bar_address = $param['bar_address'];
            } else {
                return '请输入商家地址';
            }
            if (isset($param['business_hours'])) {
                $model->business_hours = $param['business_hours'];
            } else {
                return '请选择营业时间';
            }
            if (isset($param['bar_type'])) {
                $model->bar_type = $param['bar_type'];
            } else {
                return '请选择商家类型';
            }
            if (isset($param['bar_server'])) {
                $model->bar_server = $param['bar_server'];
            }
            if (isset($param['bar_photos'])) {
                $model->bar_photos = $param['bar_photos'];
            } else {
                return '请上传图片';
            }
            if (isset($param['bar_logo'])) {
                $model->bar_logo = $param['bar_logo'];
            } else {
                return '请上传logo';
            }
            if (isset($param['bar_notice'])) {
                $model->bar_notice = $param['bar_notice'];
            }
            if (isset($param['bar_headline'])) {
                $model->bar_headline = $param['bar_headline'];
            }
            if (isset($param['bar_recommend'])) {
                $model->bar_recommend = $param['bar_recommend'];
            }
            if (isset($param['headline_url'])) {
                $model->headline_url = $param['headline_url'];
            }
            $model->is_deleted = 0;
            $model->gmt_create=date('Y-m-d H:i:s',time());
            $model->gmt_modified=date('Y-m-d H:i:s',time());

            $count = $model->insert();
            if ($count>0) {
                return json_encode(['code'=>0,'msg'=>"新建成功"]);
            } else {
                return json_encode(['code'=>1,'msg'=>"新建失败"]);
            }
        } else {
            //获取酒吧列表
            $requestGet = yii::$app->request->get();
            if ($requestGet) {
                $limit = $requestGet['limit'];
                $offset = $requestGet['offset'];
                $cityCode = -1;
                $status = -1;
                $barType = -1;
                $barName = -1;
                $startTime = -1;
                $endTime = -1;
                $barSort = -1;
                $barClaim = -1;
                if (isset($requestGet['city_code']))
                $cityCode = $requestGet['city_code'];
                if (isset($requestGet['status']))
                    $status = $requestGet['status'];
                if (isset($requestGet['bar_type']))
                    $barType = $requestGet['bar_type'];
                if (isset($requestGet['bar_name']))
                    $barName = $requestGet['bar_name'];
                if (isset($requestGet['start_time'])) {
                    $startTime = $requestGet['start_time'];
                    $endTime = $requestGet['end_time'];
                }
                if (isset($requestGet['is_claim']))
                    $barClaim = $requestGet['is_claim'];
                if (isset($requestGet['sort_type']))
                    $barSort = $requestGet['sort_type'];

                $barList = $model->getBarList($limit, $offset, $cityCode, $status, $barType, $barName, $startTime, $endTime,$barClaim,$barSort);
                return json_encode($barList);
            } else {
                //编辑商家
                $bar = yii::$app->request->post();

                $barData = Bar_bar::findOne($bar['bar_id']);
                if (isset($bar['bar_name']))
                    $barData->bar_name = $bar['bar_name'];
                if (isset($bar['city_code']))
                    $barData->city_code = $bar['city_code'];
                if (isset($bar['bar_address']))
                    $barData->bar_address = $bar['bar_address'];
                if (isset($bar['bar_address']))
                    $barData->bar_address = $bar['bar_address'];
                if (isset($bar['business_hours']))
                    $barData->business_hours = $bar['business_hours'];
                if (isset($bar['bar_type']))
                    $barData->bar_type = $bar['bar_type'];
                if (isset($bar['bar_server']))
                    $barData->bar_server = $bar['bar_server'];

                if (isset($bar['bar_photos'])) {
                    $barData->bar_photos = $bar['bar_photos'];
                }
                if (isset($bar['bar_logo'])) {
                    $barData->bar_logo = $bar['bar_logo'];
                }
                if (isset($bar['bar_notice'])) {
                    $barData->bar_notice = $bar['bar_notice'];
                }
                if (isset($bar['bar_headline'])) {
                    $barData->bar_headline = $bar['bar_headline'];
                }
                if (isset($bar['bar_recommend'])) {
                    $barData->bar_recommend = $bar['bar_recommend'];
                }
                if (isset($bar['headline_url'])) {
                    $barData->headline_url = $bar['headline_url'];
                }

                if (isset($bar['status']))
                    $barData->is_deleted = $bar['status'];
                if (isset($bar['weight_value']))
                    $barData->weight_value = $bar['weight_value'];
                $barData->gmt_modified=date('Y-m-d H:i:s',time());
                if ($barData->save() > 0) {
                    return json_encode(['code'=>0,'msg'=>"修改成功"]);
                } else {
                    return json_encode(['code'=>1,'msg'=>"修改失败"]);
                }

            }
        }
    }

    public function actionPartyList(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 152;

//        $barModel = new Bar_bar();
//        $bars = $barModel->getBars();

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();
        return $this->render('party-management/party-list',['cities'=>$cities]);
    }

    public function actionParty(){
        $requestGet = yii::$app->request->get();

        $model = new Party_party();
        if($requestGet){
            $limit = $requestGet['limit'];

            $offset = $requestGet['offset'];
            $cityCode = -1;
            $partyTheme = -1;
            $startTime = -1;
            $endTime = -1;
            $partyType = -1;
            $partyUser = -1;
            $orderBy = -1;

            if (isset($requestGet['city_code'])){
                $cityCode = $requestGet['city_code'];
            }

            if (isset($requestGet['partyrelation_length'])){
                $orderBy = $requestGet['partyrelation_length'];
            }

            if (isset($requestGet['party_theme'])){
                $partyTheme = $requestGet['party_theme'];
            }

            if (isset($requestGet['start_date'])) {
                $startTime = $requestGet['start_date'];
                $endTime = $requestGet['end_date'];
            }

            if (isset($requestGet['is_deleted'])) {
                $partyType = $requestGet['is_deleted'];
            }

            if (isset($requestGet['party_user'])) {
                $partyUser = $requestGet['party_user'];
            }

            $partyList = $model->getPartyList($limit, $offset, $cityCode, $startTime, $endTime , $partyTheme, $partyType, $partyUser, $orderBy);

            $userparty = new User_userparty();

            foreach ($partyList['rows'] as $k => $v) {
                $partyId = $v['party_id'];
                $partyrelation = $userparty->findCount($partyId);

                if ($partyrelation) {
                    $partyList['rows'][$k]['partyrelation'] = $partyrelation;
                } else {
                    $partyList['rows'][$k]['partyrelation'] = '';
                }
            }

            return json_encode($partyList);
        }else {
            $requestPost = yii::$app->request->post();
            if($requestPost){
                $party_id = $requestPost['party_id'];
                $type = $requestPost['type'];

                $party = Party_party::findOne($party_id);
                $party->is_deleted = $type;

                if($party->save() > 0){
                    return json_encode(['code'=>0,'msg'=>"修改成功"]);
                }else{
                    return json_encode(['code'=>1,'msg'=>"修改失败"]);
                }
            }
        }
    }

    public function actionUserParty(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 153;

        return $this->render('party-management/user-party');
    }

    //    加载派对聊天列表页面
    public function actionChatlistParty(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 154;

        $request = yii::$app->request->get();

        $user = User_user::findOne($request['user_id']);

        $targetUser = [];
        if(isset($request['target_user_id']))
            $targetUser  = User_user::findOne($request['target_user_id']);

        return $this->render('party-management/chat-party',['user'=>$user,'target_user'=>$targetUser]);
    }

    public function actionRegisterEase(){
        $post = yii::$app->request->post();
        $easeId = $post['ease_id'];

        $easeModel = new Easemob();

        $easeModel->createUser($easeId,"111111");

        echo json_encode(['code'=>0,'msg'=>"创建成功"]);
        exit;
    }

//    加载用户列表
    public function actionUserList(){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 112;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('user-management/user-list',['cities'=>$cities]);
    }

    // 展示用户详情
    public function actionUserDetail(){
        $request = yii::$app->request->get();
        $userId = $request['user_id'];
        $menuitemid = $request['menuitemid'];

        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = $menuitemid;

        $user = User_user::findOne($userId);

        return $this->render('user-management/user-detail',['user'=>$user]);

    }

    /*
    *   修改封禁状态
    */
    public function actionProhibition(){

        $request = yii::$app->request->post();
        $userId = $request['user_id'];
        $status = $request['status'];

        if ($status == 1) {
            $push_title = "抱歉 你的账户已经被封禁1天";
            $forbiden = "1".(time()+3600*24);
        } elseif ($status == 2) {
            $push_title = "抱歉 你的账户已经被封禁5天";
            $forbiden = "2".(time()+3600*24*5);
        } elseif ($status == 3) {
            $push_title = "抱歉 你的账户已经被封禁。如有疑问，请联系热城客服。";
            $forbiden = "39999999999";
        } else {
            $push_title = "";
            $forbiden = "0";
        }

        $userModel = new User_user;
        $result = $userModel->editStatus($userId, $forbiden);

        if($status != 0){
            $commonModel = new CommonHelper();
            $easeIdPre = $commonModel->getEaseIdPre();

            $hxModel = new Easemob();
            $result = $hxModel->sendText($easeIdPre.$userId,"ETM_LIMIT",$push_title,$push_title);

            echo json_encode($result);
            exit;
        }


        if($result > 0){
            return json_encode(['code'=>0,'msg'=>"修改成功"]);
        }else{
            return json_encode(['code'=>1,'msg'=>"修改失败"]);
        }
    }

    // 加载充值页面
    public function actionPayList (){
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 142;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('pay-management/pay-list',['cities'=>$cities]);
    }

//  执行新增分组
    public function actionAddGroup() {
        $requestPost = yii::$app->request->post();
        $sortName = $requestPost['sort_name'];

        $model = new User_sort();
        $model->sort_name = $sortName;

        if  ($model->insert() > 0) {
            return json_encode(['code'=>0,'msg'=>'添加成功']);
        } else {
            return json_encode(['code'=>1, 'msg'=>'添加失败']);
        }
    }

    // 员工列表也展示
    public function actionStaffList() {
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 103;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('staff-management/staff-list',['cities'=>$cities]);
    }

    // 查找员工列表
    public function actionStaff() {
        $request = yii::$app->request->get();
        $model = new admin_admin();

        $limit = $request['limit'];
        $offset = $request['offset'];
        
        $staffList = $model->findAdmin($limit, $offset);
        return json_encode($staffList);
    }

    // 添加员工
    public function actionAddStaff() {
        $request = yii::$app->request->post();
        $model = new Admin_admin();

        $model->mobile = $request['mobile'];
        $model->password = md5($request['password']);
        $model->type = 3;
        $model->dynamic_password = 1357;
        $model->LoadingScreenUrl = 'http://img.zcool.cn/community/0125fd5770dfa50000018c1b486f15.jpg@1280w_1l_2o_100sh.jpg';
        $model->party_count = 3876;

        $result = $model->insert();

        if ($result > 0) {
            return json_encode(['code' => 0, 'msg' => '添加成功']);
        } else {
            return json_encode(['code' => 1, 'msg' => '添加失败']);
        }
    }

    // 编辑员工
    public function actionEditStaff() {
        $request = yii::$app->request->post();
        $adminId = $request['admin_id'];
        $status = -1;
        $pwd = -1;
        $type = -1;

        if (isset($request['is_deleted'])) {
            $status = $request['is_deleted'];
        } 

        if (isset($request['password'])) {
            $pwd = md5($request['password']);
        }

        if (isset($request['admin_type'])) {
            $type = $request['admin_type'];
        }

        $model = new Admin_admin();
        $result = $model->editAdmin($adminId, $status, $pwd, $type);

        if ($result) {
            return json_encode(['code' => 0, 'msg' => '更新成功']);
        } else {
            return json_encode(['code' => 1, 'msg' => '更新失败']);
        }
    }

    // 显示员工编辑页面
    public function actionShowStaff() {
        $request = yii::$app->request->post();
        $adminId = $request['admin_id'];
        $model = new Admin_admin();

        $result = $model->findStaff($adminId);

        return json_encode($result);
    }

    // 加载商家入驻申请列表页面
    public function actionMerchantEntry() {
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 173;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('bar-management/business-list',['cities'=>$cities]);
    }

    // 查找入驻商家信息
    public function actionBusiness() {
        $request = yii::$app->request->get();
        $model = new Bar_claim();
        $limit = $request['limit'];
        $offset = $request['offset'];
        $isPass = -1;
        $barType = -1;
        $barName = -1;
        $startTime = -1;
        $endTime = -1;
        $examineStart = -1;
        $examineEnd = -1;

        if (isset($request['examine_start'])) {
            $examineStart = $request['examine_start'];
            $examineEnd = $request['examine_end'];
        }

        if (isset($request['start_date'])) {
            $startTime = $request['start_date'];
            $endTime = $request['end_date'];
        }

        if (isset($request['is_pass'])) {
            $isPass = $request['is_pass'];
        }

        if (isset($request['bar_type'])) {
            $barType = $request['bar_type'];
        }

        if (isset($request['bar_name'])) {
            $barName = $request['bar_name'];
        }

        $businessList = $model->getBusinessList($limit, $offset, $isPass, $barType, $barName, $endTime, $startTime, $examineEnd, $examineStart);
        return json_encode($businessList);
    }

    // 审核商家入驻
    public function actionBusPass() {
        $request = yii::$app->request->post();
        $model = new Bar_claim();
        $barId = -1;
        $claimId = $request['claim_id'];
        $isPass = $request['status'];
        if (isset($request['bar_id'])) {
            $barId = $request['bar_id'];
        }

        $result = $model->editPass($claimId, $isPass, $barId);

        if ($result == 1) {
            return json_encode(['code' => 0, 'msg' => $result]);
        } elseif ($result == 3) {
            return json_encode(['code' => 2, 'msg' => '该酒吧已被认领']);
        } else {
            return json_encode(['code' => 1, 'msg' => '修改失败']);
        }
    }

    // 展示广告列表页
    public function actionBannerList() {
        $this -> confirmAdmin();
        $view = Yii::$app->view;
        $view->params['menuitemid'] = 104;

        $cityModel = new Gl_city();
        $cities = $cityModel->getCities();

        return $this->render('banner-management/banner-list',['cities'=>$cities]);
    }

    // 获取广告列表数据
    public function actionBanner(){
        $request = yii::$app->request->get();
        $model = new Gl_banner();
        if ($request) {
            //获取广告列表
            $limit = $request['limit'];
            $offset = $request['offset'];

            $bannerList = $model->getBannerList($limit, $offset);
            return json_encode($bannerList);
        } else {
            //更新广告资料
            $requestPost = yii::$app->request->post();
            if ($requestPost) {
                $bannerId = $requestPost['banner_id'];
                $isDeleted = -1;
                $bannerType = -1;
                $bannerPic = -1;
                $bannerUrl = -1;
                $weightValue = -1;

                if (isset($requestPost['status'])){
                    $isDeleted = $requestPost['status'];
                }
                if (isset($requestPost['banner_type'])){
                    $bannerType = $requestPost['banner_type'];
                }
                if (isset($requestPost['banner_pic'])){
                    $bannerPic = $requestPost['banner_pic'];
                }
                if (isset($requestPost['banner_url'])){
                    $bannerUrl = $requestPost['banner_url'];
                }
                if (isset($requestPost['weight_value'])){
                    $weightValue = $requestPost['weight_value'];
                }

                $updateDone = $model->updateBanner($bannerId, $isDeleted, $bannerType, $bannerPic, $bannerUrl, $weightValue);
                if ($updateDone) {
                    return json_encode(['code'=>0,'msg'=>"更新成功"]);//更新成功
                } else {
                    return json_encode(['code'=>1,'msg'=>"更新失败"]);
                }
            }
        } 
    }

    // 添加广告位
    public function actionAddBanner (){
        //新建奖品
        $requestPost = yii::$app->request->post();
        $model = new Gl_banner();

        $model->banner_type = $requestPost['banner_type'];
        $model->banner_pic = $requestPost['banner_pic'];
        $model->banner_url = $requestPost['banner_url'];
        $model->weight_value = $requestPost['weight_value'];
        $model->is_deleted = 0;
        $model->gmt_create=date('Y-m-d H:i:s',time());
        $model->gmt_modified=date('Y-m-d H:i:s',time());

        $count = $model->insert();
        if ($count > 0) {
            return json_encode(['code'=>0,'msg'=>"新建成功"]);
        } else {
            return json_encode(['code'=>1,'msg'=>"新建失败"]);
        }
    }

    // 查询编辑页面所需数据
    public function actionBannerEdit() {
        $requestPost = yii::$app->request->post();
        $model = new Gl_banner();
        $banner_id = $requestPost['banner_id'];

        $editBanner = $model->editBanner($banner_id);
        return json_encode($editBanner);
    }

    // 显示所有广告图
    public function actionShowBanner(){
        $model = new Gl_banner();
        $result = $model->showBanner();

        return json_encode($result);
    }

    // 选择广告图
    public function actionSetBanner(){
        $request = yii::$app->request->post();
        $model = new Admin_admin();
        $adminId = $request['admin_id'];
        $bannerPic = $request['banner_pic'];

        $result = $model->setBanner($adminId, $bannerPic);

        if ($result) {
            return json_encode(['code'=>0,'msg'=>"设置成功"]);
        } else {
            return json_encode(['code'=>1,'msg'=>"设置失败"]);
        }
    }
}